package edu.xlh.travel.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class RedisPipelined {
    @Autowired
    private  RedisTemplate redisTemplate;

    public  String getCaptcha (String verKey) {
        List byteList=  redisTemplate.executePipelined(new RedisCallback<Object>() {
            @Override
            public Object doInRedis(RedisConnection redisConnection) throws DataAccessException {

                redisConnection.openPipeline();

                redisConnection.get(verKey.getBytes());

                return null;
            }
        }, RedisSerializer.string());
        String value = (String)byteList.get(0);
        return value;
    }
}
